package mail;

import java.util.*;
import subjectAndProfessorship.EnrolledInProfessorship;

/**
 * Aqui se almacena el trafico de mails del sistema.
 * @author Damian
 *
 */
public class RegistrationEmails {
	
	private static RegistrationEmails instance;
	private List<Mail> emails = new Vector<Mail>();
	
	
	public static RegistrationEmails getInstance (){
		if(RegistrationEmails.instance == null)
			RegistrationEmails.instance = new RegistrationEmails();
		return RegistrationEmails.instance;
	}
	
	/**
	 * Retorna la lista de mails que se generaron.
	 * @return
	 */
	public List<Mail> getEMails(){
		return this.emails;
	}
	
	/**
	 * Agrega un email a la lista.
	 * @param email
	 */
	public void sendEmail(Mail email){
		emails.add(email);
	}
	
	/**
	 * Retorna la lista de mails que pasaron el filtro.
	 * @param filtro
	 * @return
	 */
	public List<Mail> filterBy (SearchType tag){
		List<Mail> emails = new Vector<Mail>();
		for(Mail e : emails){
			if(tag.filter(e))
				emails.add(e);
		}			
		return emails;
	}
	/**
	 * Envia un mail a todos los estudiantes de una catedra.
	 * @param alumnos
	 * @param email
	 */
	public void sendEmailsAll (List<EnrolledInProfessorship> alumnos, Mail email) {
		for (EnrolledInProfessorship alumno : alumnos) {
			this.sendEmail((Mail) email.clone()); 
			alumno.agregarMail((Mail) email.clone());
		}
	}

}
